<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_DataGrid_Renderer
 * @subpackage Html
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */


/** @see Zend_DataGrid_Renderer_Html */
require_once 'Zend/DataGrid/Renderer/Html.php';


/**
 * Zend_DataGrid_Renderer_Html_Template
 *
 * @category   Zend
 * @package    Zend_DataGrid_Renderer
 * @subpackage Html
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Template.php 8862 2008-11-09 15:36:00Z azoungrana $
 */
class Zend_DataGrid_Renderer_Html_Template extends Zend_DataGrid_Renderer_Html
{

    /**
     * Renders the header
     *
     * @return string
     */
    public function renderHeader()
    {
        return '<th ' . $this->_htmlAttribs($this->_options['headerAttributes']) . '>' . $this->_gridElement->getHeaderTemplate() . '</th>';
    }

    /**
     * Renders the cell
     *
     * @param mixed $data
     * @param boolean $isAlternatingItem when item is alternating
     * @return string
     */
    public function renderItem($data, $isAlternatingItem = false)
    {
        $htmlAttribs = null;
        if ($isAlternatingItem) {
            $htmlAttribs = $this->_options['alternatingItemAttributes'];
        } else {
            $htmlAttribs = $this->_options['itemAttributes'];
        }

        $content = $this->_gridElement->getItemTemplate();
        foreach ($data as $i=>$d) {
            $content = str_ireplace('%%'.$i.'%%',$d,$content);
        }

        return '<td ' . $this->_htmlAttribs($htmlAttribs) . '>' . eval("$content") . '</td>';
    }

    /**
     * Renders the footer
     *
     * @return string
     */
    public function renderFooter()
    {
        return '<th ' . $this->_htmlAttribs($this->_options['footerAttributes']) . '>' . $this->_gridElement->getFooterTemplate() . '</th>';
    }

}




